package com.chuangjiangx.member.basic.ddd.dal.dto;

import lombok.Getter;
import lombok.Setter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author cj-ch
 * @date 2018/6/19 下午6:10
 * 按时间占比
 */

public class TimeScales extends MbrCount{
    SimpleDateFormat hourFormat = new SimpleDateFormat("yyyyMMddHH");
    SimpleDateFormat dayFormat = new SimpleDateFormat("yyyyMMdd");
    /**
     * 时间
     */
    private Date time;

    /**
     * 时间字符串表示
     * 例如:小时-"2018060606"
     *      天 - "20180606"
     */
    @Setter
    @Getter
    private String timeStr;

    public Date getTime() {
        if(null == timeStr || timeStr.trim().length() < 8){
            return null;
        }
        Date date = null;
        try {
            if(8 == timeStr.length()){
                 date = dayFormat.parse(timeStr);
            }else{
                date = hourFormat.parse(timeStr);
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    public static void main(String[] args) throws ParseException {
        String str = "2018060609";
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH");
        Date parse = dateFormat.parse(str);
        System.out.println(parse);
    }
}
